package com.zkthink.ceres.applet.commission.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zkthink.ceres.applet.commission.domain.entry.AppletCommission;
import org.apache.ibatis.annotations.Select;

import java.math.BigDecimal;

/**
 * @Author cmz
 * @Date 2024-05-14 15:32
 */
public interface AppletCommissionMapper extends BaseMapper<AppletCommission> {
    /**
     * 获取当天的直接推荐人员提成
     * @param mid
     * @return
     */
    @Select("select ifnull(sum(ifnull(ac.direct_commission,0)),0) from  applet_commission ac where date(ac.create_time) = CURDATE() and mid in ( select id from ceres_member cm where cm.refer_phone = (select phone from ceres_member cmm where id = #{mid}) ) ")
    BigDecimal selectTodayDirectCommission(Long mid);

    /**
     * 获取当天的间接推荐人员提成
     * @param mid
     * @return
     */
    @Select("select ifnull(sum(ifnull(ac.indirect_commission,0)),0) from applet_commission ac where date(ac.create_time) = CURDATE() and mid in ( select id from ceres_member cm where cm.refer_phone in ( select phone from ceres_member cmm where cmm.refer_phone = ( select phone from ceres_member cmmm where cmmm.id = #{mid} ) ) )")
    BigDecimal selectTodayInDirectCommission(Long mid);
    
    
    @Select("select ifnull(sum(ifnull(ac.direct_commission,0)),0) from  applet_commission ac where mid in ( select id from ceres_member cm where cm.refer_phone = (select phone from ceres_member cmm where id = #{mid}) ) ")
    BigDecimal selectDirectCommission(Long mid);

    @Select("select ifnull(sum(ifnull(ac.indirect_commission,0)),0) from applet_commission ac where mid in ( select id from ceres_member cm where cm.refer_phone in ( select phone from ceres_member cmm where cmm.refer_phone = ( select phone from ceres_member cmmm where cmmm.id = #{mid} ) ) )")
    BigDecimal selectInDirectCommission(Long mid);


}